﻿' ------------------------------------------------------------------------------
' The OnDragDrop helper method scans the DragEventArgs for file names and makes a list
' of unique jpeg file names. If the list is not empty, it is passed to the image loader.
'
' These helper methods provide standardized handling for DragDrop and DragEnter events.
' Forms and controls that can accept these events add handlers that route the events
' to these modules.
' ------------------------------------------------------------------------------
' This file is part of the SQL Server 2008 Technology Demonstration. This
' application was designed and coded by Eric Weitzman, LandTime Inc, for
' Microsoft Corporation. Contact Ed Katibah at Microsoft about this demo.
' Copyright © 2008 Microsoft Corporation. All rights reserved.
' ------------------------------------------------------------------------------

Module DragDropHelper

    Public Sub OnDragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs)
        Dim files As New ArrayList
        For Each datatype As String In (New String() {"FileDrop", "FileName", "FileNameW"})
            Dim drop As Object = e.Data.GetData(datatype)
            Try
                For Each file As String In CType(drop, String())
                    file = IO.Path.GetFullPath(file) ' convert 8.3 paths to fully expanded paths to avoid adding duplicates
                    If ImageType(file) = SpatialAlbum.Core.Enums.EnumImageType.eJpg AndAlso Not files.Contains(file) Then files.Add(file)
                Next
            Catch ex As Exception
            End Try
        Next
        If files.Count = 0 Then Return

        g_loaderform.Show()
        g_imageloader.AddImages(files, g_connection)
    End Sub

    Public Sub OnDragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs)
        e.Effect = DragDropEffects.Copy
    End Sub

End Module
